﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;

namespace Utilities
{
    public class Template
    {
        public Template()
        {
            StartDelimiter = '$';
            EndDelimiter = '$';
        }

        #region Public properties

        /// <summary>
        /// The text of the template to process
        /// </summary>
        public string Text { get; set; }

        public char StartDelimiter { get; set; }

        public char EndDelimiter { get; set; }

        #endregion

        public string Apply(IDictionary<string, object> values)
        {
            //PreCondition.RequireNotNullOrEmpty(Key, "Key must be provided");
            PreCondition.RequireNotNullOrEmpty(Text, "Text must be provided");

            if (_templateData == null)
            {
                _templateData = TemplateData.Compile(Text, StartDelimiter, EndDelimiter);
            }

            return _templateData.Apply(values);
        }

        /// <summary>
        /// The compiled template
        /// </summary>
        private TemplateData _templateData;
    }
}
